package com.wzt.lianfirecontrol.adapter.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.adapter.BaseRecyclerAdapter;
import com.wzt.lianfirecontrol.bean.recode.BannerModel;

public class BarTitleAdapter extends BaseRecyclerAdapter<BannerModel> {

    private int currentPosition = 0;

    public int getCurrentPosition() {
        return currentPosition;
    }

    public void setCurrentPosition(int currentPosition) {
        this.currentPosition = currentPosition;
        notifyDataSetChanged();
    }

    private Context context;

    public BarTitleAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_bar_title, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, BannerModel data) {
        if (viewHolder instanceof MyViewHolder){
            setItemData((MyViewHolder)viewHolder, data, RealPosition);
        }
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView tv_title;
        private View v_line;
        public MyViewHolder(View itemView) {
            super(itemView);
            initItemView(this, itemView);
        }
    }

    private void initItemView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.tv_title = itemView.findViewById(R.id.tv_title);
        myViewHolder.v_line = itemView.findViewById(R.id.v_line);
    }

    private void setItemData(MyViewHolder myViewHolder, BannerModel bannerModel, int positon){
        myViewHolder.tv_title.setText(bannerModel.getTitle());
        if (positon == currentPosition){
            myViewHolder.tv_title.setTextColor(context.getResources().getColor(R.color.white));
            myViewHolder.tv_title.getPaint().setFakeBoldText(true);
            myViewHolder.v_line.setVisibility(View.VISIBLE);
        }else {
            myViewHolder.tv_title.setTextColor(context.getResources().getColor(R.color.divider_line_color));
            myViewHolder.tv_title.getPaint().setFakeBoldText(false);
            myViewHolder.v_line.setVisibility(View.INVISIBLE);
        }
    }
}
